package org.example.zuul.filter.route;

import org.example.zuul.filter.ZuulFilter;
import org.example.zuul.http.RequestContext;
import org.springframework.http.RequestEntity;
import org.springframework.web.client.RestTemplate;

public class RoutingFilter implements ZuulFilter {
    RestTemplate restTemplate = new RestTemplate();

    @Override
    public void run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        RequestEntity<?> requestEntity = ctx.getRequestEntity();
        if (requestEntity != null) {
            ctx.setResponseEntity(restTemplate.exchange(requestEntity, byte[].class));
        }
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public String filterType() {
        return ZuulFilter.TYPE_ROUTE;
    }
}
